package ru.aslanov.schedule.model;

import ru.aslanov.schedule.utils.XMLUtil;

import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.datatype.DatatypeConstants;
import javax.xml.datatype.XMLGregorianCalendar;
import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 * Created: Jan 22, 2010 3:24:47 PM
 *
 * @author Sergey Aslanov
 */
public class XmlDate2DateAdapter extends XmlAdapter<XMLGregorianCalendar, Date>{

    @Override
    public Date unmarshal(XMLGregorianCalendar v) throws Exception {
        return v.toGregorianCalendar().getTime();
    }

    @Override
    public XMLGregorianCalendar marshal(Date v) throws Exception {
        if (v == null) return null;        
        return XMLUtil.date2XmlDate(v, DatatypeConstants.DATE);
    }
}
